################################################################################ 
################################################################################ 
#################### Meta-analysis on the Contact Hypothesis ###################
################################################################################ 
################################################################################ 

# This script is the master script 
# for the project 
# Meta-analysis on the Contact Hypothesis
# by Gwen-Jiro Clochard

rm(list = ls(all.names = TRUE))


################################################################################ 
############################## Packages ######################################## 
################################################################################ 

vec.pac= c("foreign", "quantreg", "gbm", "glmnet",
           "MASS", "rpart", "doParallel", "sandwich", "randomForest",
           "nnet", "matrixStats", "xtable", "readstata13", "car", "lfe", "doParallel",
           "caret", "foreach", "multcomp","cowplot", "haven", "readxl", "plyr", 
           "tidyr", "writexl", "modeest", "RCT", "knitr", "plm", "stargazer",
           "broom","miceadds", "DescTools", "psych", "gt", "hrbrthemes",
           "plotrix", "missForest", "tidyverse",
           "units", "sf", "maps", "rnaturalearth", "geosphere", "psych", "openxlsx",
           "blockrand", "terra", "spData", "tmap", "gplots", "scales", "car", "ggrepel",
           "rtweet", "Hmisc", "texreg", "stringr", "inters", "ggpubr", "meta",
           "zoom", "clubSandwich", "AER", "patchwork", "purrr", "hdm"
)

new.packages <- vec.pac[!(vec.pac %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

lapply(vec.pac, require, character.only = TRUE) 

library(psych)
library(DescTools)
library(data.table)
library(xtable)
library(RCT)
library(knitr)
library(stargazer)
library(broom)
library(ggplot2)
library(hrbrthemes)
library(plotrix)
library(glmnet)
library(missForest)
library(randomForest)
library(dplyr)
library(lmtest)
library(tidyverse)
library(sandwich)
library(miceadds)
library(maps)
library(sf) 
library(units)
library(rnaturalearth)
library(geosphere)
library(openxlsx)
library(blockrand)
library(spData)
library(gplots)
library(scales)
library(car)
library(ggrepel)
library(texreg)
library(stringr)
library(meta)
library(zoom)
library(metafor)
library(clubSandwich)
library(AER)
library(patchwork)
library(cowplot)
library(purrr)
library(hdm)


# Take only last part of a string

substrRight <- function(x, n){
  substr(x, nchar(x)-n+1, nchar(x))
}

rm(new.packages, vec.pac)


################################################################################ 
##################################### Paths ####################################
################################################################################ 

# This section gets the right paths for different actions

pathresearch <- "C://Users//gwengiro//Dropbox//Recherche//"
# pathresearch <- "C://Users//User//Dropbox//Recherche//"
pathproject <- paste(pathresearch,"Contact_Meta//", sep = "")
pathscripts <- paste(pathproject,"3. Do-files", sep = "")
pathdata <- paste(pathproject,"2. Data", sep = "") 
pathtables <- paste(pathproject,"5.Tables", sep = "")
pathfigures <- paste(pathproject,"4. Figures", sep = "")


# Define the meta packages
source(file.path(pathscripts, "utils.R"))
